/*******************************************************************************
*  COPYRIGHT LIPUJUN TECH CO.,LTD
********************************************************************************
* 文件名称:  task.h
* 功能描述:
* 使用说明:  无
* 文件作者:  LIPUJUN
* 编写日期:  2018/11/28
* 修改历史:
* 修改版本  修改日期       修改人   修改内容
* ------------------------------------------------------------------------------
  01a       2018/11/28        李普军   创建
*******************************************************************************/

/******************************** 头文件保护开头 *****************************/
#ifndef __COMMON_H /* 头文件保护 */
#define __COMMON_H /* 头文件保护 */

/******************************** 类型定义 ***********************************/
//#define _XOPEN_SOURCE 
#include "slog.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <semaphore.h>
#include <dirent.h>
//#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <linux/spi/spidev.h>
#include <memory.h>
#include <pthread.h>
#include <sys/time.h>
#include <signal.h>
#include <time.h>
#include <sys/vfs.h>

#ifndef OK
#define OK         (0)    /* 成功 */
#endif
#ifndef false
#define false 	   (0)
#endif
#ifndef true
#define true 	   (1)
#endif

#ifndef ERROR
#define ERROR      (-1)   /* 失败 */
#endif

#undef NULL
#define NULL ((void *)0)

typedef	unsigned char		UINT8;
typedef	char		        INT8;
typedef	short		        INT16;
typedef	int		        INT32;
typedef	long    	        INT64;
typedef	unsigned char	    	UINT8;
typedef	unsigned short	    	UINT16;
typedef	unsigned int	    	UINT32;
typedef	unsigned long long  	UINT64;
typedef	int		        BOOL;
typedef	int		        STATUS;
typedef char                	CHAR;

#define DATA_STORE_BASE_PATH            "/upload"
#define UNIFY_BASE_PATH                 "/upload/dataSet"
#define BOND_CHECK_ENABLE               "/tmp/.bondCheck.tmp"
#define ETHERNET_SPEED_FILE             "/tmp/.bond0speed.tmp"
#define BLOCK_MIN_SIZE	                 2
#define UPLOAD_BASEPATH                 "/upload/data"
#define SYS_DEFAULT_CONFIG              "/AIR_FLASH/system/air_sys.conf"
#define SH_ISLINK                       "/tmp/.isLink.tmp"
#define UPLOADBlock_SIZEF               "/upload/data/.uploadDataSize"
#define REGSub6ATimeFlg                 "/tmp/.reg6AsubTime"
#define SHELL_LOG                       "/upload/log/sh.log"
#define A6List_LOG                      "/upload/log/A6List.log"
#define UpanList_LOG                    "/upload/log/uploadUpan.log"
#define ONOFF_timeProfile               "/upload/log/.profile"
#define ONOFF_timesFile                 "/upload/log/.onofftimes"
#define lastNewGroupTime                "lastGroupTime"
#define lastPowerTimeLen                "lastPowerTime"
#define lastVideoSize                   "lastVideoSize"
#define VIDEO_BLOCK_MIN_SIZE            10   //MB
#define GROUP_MIN_SIZE                  2  //2GB
#define VIDEO_SOURCE                    "video" 
#define VIDEO_BLOCK                     "block"
#define VIDEO_GROUP                     "group"
#define VIDEO_CONF                      ".profile"
#define MSG_QUEUE_MAX_NUM               512
#define MSG_QUEUE_DATA_LEN              4096
#define VIDEO_FILELISTS                 ".filesList"
#define A6_PATH                         "/6A"
#define LINE_CONTENT_MAX_LEN            128
#define ARGV_MAX_LEN                    LINE_CONTENT_MAX_LEN
#define AIR_DEFAULT_CONFIG              "/AIR_FLASH/script/air.conf"
#define AIR_VERSION                     "/AIR_FLASH/system/air_version.conf"
#define CONNECT_FAIL_LOG_Interval       10
#define APP_UPGRADE_SH                  "/AIR_FLASH/script/upgrade.sh"
#define APP_SETUP_FILE                  "setup.sh"
#define APP_ROLLBACK_SH                 "/AIR_FLASH/script/rollback.sh"
#define APP_MD5_CHECK                   "/AIR_FLASH/script/md5_checker.sh"
#define APP_POE                         "/AIR_FLASH/script/poe.sh"
#define BLOCK_MAX_COUNT                 512

#define LOG_DEFAULT_LEVEL               S_INFO
#define LOG_DEFAULT_MAX_SIZE            128  //128MB
#define SYSTEM_LOG_PATH                 "/upload/log"

INT8* currentTimeGet (void);
void htkj_log(const char *func_name, int line, const char *fmt, ...);

#define LOG(fmt, ...)   write_log(S_OFF, false, NULL, __LINE__, fmt, ##__VA_ARGS__);htkj_log(NULL, __LINE__, fmt, ##__VA_ARGS__);
#define INFO(fmt, ...)  write_log(S_INFO, false, NULL, __LINE__, fmt, ##__VA_ARGS__);htkj_log(NULL, __LINE__, fmt, ##__VA_ARGS__);
#define Error(fmt, ...) write_log(S_ERROR, false, __FUNCTION__,__LINE__,fmt, ##__VA_ARGS__);htkj_log(__FUNCTION__, __LINE__, fmt, ##__VA_ARGS__);

INT8* currentTimeGet (void); 
UINT32 currentTimeGet_int (void);
UINT32 strTime2Int(const char* sTime);
INT8* intTime2Str(UINT32 iTime ,INT8* sTime);

void printBootLogo (UINT32 type);
void printLogo (void);
void printClientInfo (void);
void log_upload_prepare(const char*path);
INT32 htkj_system(char * format,...);
INT32 systemOut(const char *cmd, char *result,INT32 size);
INT32 get_diskSize (CHAR* disk_total);
INT32 get_localMAC (CHAR *mac, CHAR *name);
INT32 get_ipByEthN (const CHAR *name,CHAR *ip);
INT32 get_localIPByRemoteIP (const CHAR *dstIP,CHAR *ip,int mask);

INT32 fileSize(const INT8* fname);
INT32 setKeyValue_str(const INT8 * key,INT8 *value);
INT32 setKeyValue_int(const INT8* key,INT32 value);
INT32 rmKeyValue(const INT8 *key);
INT32 com_rmKeyValue(const INT8 *key,const INT8 *filename);
INT8* com_getKeyValue(const INT8* key,INT8* value,const INT8 * filename);
INT32 com_setKeyValue(const INT8* key,const INT8* value,const INT8 *filename);
BOOL readConfig(const INT8* path);

void delEmptyDir(const INT8* path);
int file_lastTime(const char* basePath);
INT32 getSpeed();
UINT64 getPathDataSize(const char* path);
UINT64 getPathData_realSize(const char* path);
INT32 getPathFilesCount(const char* path);
void init_system(void);
UINT8 getUSBDisk(void);
UINT32 getUSBDiskPlugTimes(UINT8 flg);
int divide_block(void);
int divide_group(void);
int sort_dir(const char* basePath,const char* pathName ,int index[]);
void setPOE(int flg);//1:on 0:off
void clearFile(const INT8* fname);
void dirBySuffix_link(const INT8* sDir,const INT8* dDir,const INT8* suffix);

/******************************** 头文件保护结尾 *****************************/
#endif /* __TASK_H *//* 头文件保护 */
/******************************** 头文件结束 *********************************/
